<?php
namespace Home\Controller;
use Think\Controller;
class ListController extends CommonController {
    public function index(){
		/*获得父级分类*/
		$cid=I('get.cid',null,'intval');
		$cate=M('category')->select();
		$parentCate=$this->parent_cate($cate, $cid);
		
		
		/*面包屑*/
		$this->assign('mbx',array_reverse($parentCate));

		
		/*分类查找*/
		$cateCid=I('get.cid',0,'intval');      //如果cid不存在设置为0
		$cateDB=M('category')->where(array('pid'=>$cateCid))->select();
		$pid=M('category')->where(array('cid'=>$cateCid))->getField('pid');
		if(!$cateDB){//判断  如果子栏目不存在的时候
			$cateDB=M('category')->where(array('pid'=>$pid))->select();
		}
		$this->assign('cateCid',$cateCid);
		$this->assign('cateDB',$cateDB);
		
		
		/*tab 待解决问题 已解决 高悬赏 零回答*/
		$where=I('get.where',0,'intval');
		$askDB=D('ask');
		$field='content,time,answer,gold,cname,asid';
		switch ($where) {
			case 0:
				$wherecon=array('solve'=>0);
				$count=$askDB->where($wherecon)->count();
				break;
			case 1:
				$wherecon=array('solve'=>1);
				$count=$askDB->where($wherecon)->count();
				break;
			case 2:
				$wherecon=array('solve'=>0,'gold'=>array('GT',5));
				$count=$askDB->where($wherecon)->count();
				break;
			case 3:
				$wherecon=array(array('solve'=>0,'ask.answer'=>0));
				$count=$askDB->where($wherecon)->count();
				break;		
			default:
				break;
		}
		if($cateCid!=0){
			$wherecon['ask.cid']=$cateCid;
		}
		$page=new \Think\Page($count,6);
		$this->assign('page',$page->show());
		$solving=$askDB->field($field)->where($wherecon)->limit($page->firstRow.','.$page->listRows)->order('time desc')->select();
		$this->assign('empty',"<tr><td colspan='3'>暂时没有数据</td></tr>");
		$this->assign('solving',$solving);
		
		
    	$this->display('list');
    }
}



